#include "mq_connection.hpp"

int main(){
    //实例化异步工作线程对象
    yqx::AsyncWorker::ptr awp = std::make_shared<yqx::AsyncWorker>();
    //实例化连接对象
    yqx::Connection::ptr conn = std::make_shared<yqx::Connection>("127.0.0.1", 8085, awp);
    //通过连接创建信道
    yqx::Channel::ptr channel = conn->openChannel();
    //通过信道提供的服务完成所需
    channel->declareExchange("exchange1", yqx::ExchangeType::FANOUT, true, false);
    channel->declareQueue("queue1", true, false, false);
    channel->declareQueue("queue2", true, false, false);
    channel->bind("exchange1", "queue1", "queue1");
    channel->bind("exchange1", "queue2", "news.music.#");
    //循环向交换机发布消息
    for(int i = 0; i < 10; ++i){
        channel->basicPublish("exchange1", nullptr, "Hello World-" + std::to_string(i));
    }
    //关闭信道
    conn->closeChannel(channel);
    return 0;
}